part of '../animation.dart';

/// 这类动画就是只用一个double seconds来控制
/// 它会永久性地setState
class AnimationForever extends StatefulWidget {
  final Widget Function(double seconds) builder;
  const AnimationForever({required this.builder, super.key});

  @override
  State<AnimationForever> createState() => _AnimationForeverState();
}

class _AnimationForeverState extends State<AnimationForever> {
  int seconds = 0;

  @override
  Widget build(BuildContext context) {
    return AnimationFast(
      init: (ctrl) {
        ctrl.forward();
        ctrl.addStatusListener((status) {
          if (status == AnimationStatus.completed) {
            seconds++;
            ctrl.reset();
            ctrl.forward();
          }
        });
      },
      builder: (ctrl) {
        return widget.builder(seconds + ctrl.value);
      },
    );
  }
}
